package com.flc.archive;

import com.flc.archive.writer.DataWriter;
import com.flc.archive.writer.TimerManager4File;
import com.flc.archive.config.AppConfig;
import com.flc.archive.mq.consumer.*;
import org.apache.rocketmq.client.exception.MQClientException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * 设备上报数据归档程序
 * @author haizi
 * @date 2018-2-2日
 */
public class Archive {

    private static final Logger logger = LoggerFactory.getLogger(Archive.class);

    public static DataWriter reportWriter;
    public static DataWriter trajectoryWriter;
    public static DataWriter diagnosisWriter;
    //public static DataWriter simpleWriter;

    public static void main( String[] args ) {

        Consumer reportConsumer = ConsumerFactory.getConsumer(ReportConsumer.class);
        Consumer trajectoryConsumer = ConsumerFactory.getConsumer(TrajectoryConsumer.class);
        Consumer diagnosisConsumer = ConsumerFactory.getConsumer(DiagnosisConsumer.class);
        Consumer simpleConsumer = ConsumerFactory.getConsumer(SimpleConsumer.class);

        AppConfig.FileCfg fileCfg = AppConfig.getInstance().getFileCfg();
        AppConfig.HdfsCfg hdfsCfg = AppConfig.getInstance().getHdfsCfg();

        try {
            simpleConsumer.start();
            trajectoryConsumer.start();
            reportConsumer.start();
            diagnosisConsumer.start();

            reportWriter = new DataWriter(1000, fileCfg.getReportPath(), hdfsCfg.getReportHdfsPath());
            trajectoryWriter = new DataWriter(1000, fileCfg.getTrajectoryPath(), hdfsCfg.getTrajectoryHdfsPath());
            diagnosisWriter = new DataWriter(1000, fileCfg.getDiagnosisPath(), hdfsCfg.getDiagnosisHdfsPath());
            //simpleWriter = new SimpleConsumer(1000, fileCfg.getSimpleWriter());

            //定时切换文件程序开启
            new TimerManager4File();

        } catch (MQClientException e) {
            logger.error("未能打开MQ客户端的错误");
            e.printStackTrace();
        } catch (IOException e) {
            logger.error("未能打开文件的错误");
            e.printStackTrace();
        }


    }
}
